﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HenIT.CAGCompare
{
    public class GACMatrix
    {
        public List<string> Machines { get; set; }
        public List<GACMatrixEntry> gacMatrixEntries = new List<GACMatrixEntry>();
    }

    public class GACMatrixEntry : IComparable
    {
        #region Constructor
        public GACMatrixEntry() { }
        public GACMatrixEntry(string assemblyName, string version, string culture, string publicKeyToken, string gacType)
        {
            assemblyName = ToTitle(assemblyName, '.');
            GACEntryName = string.Format("{0} ({1}, {2}, {3}, {4})",
                            assemblyName, version, culture, publicKeyToken, gacType);
        }
        public GACMatrixEntry(string assemblyName, string version, string culture, string publicKeyToken, long fileSizeBytes, string gacType)
        {
            assemblyName = ToTitle(assemblyName, '.');
            GACEntryName = string.Format("{0} ({1}, {2}, {3}, {4} KB, {5})",
                            assemblyName, version, culture, publicKeyToken, (fileSizeBytes / 1024), gacType);
        }
        #endregion
    
        public string GACEntryName { get; set; }
        public string EntryPath { get; set; }
        public List<string> Machines { get; set; }

        #region IComparable Members
        public int CompareTo(object gacMatrixEntry2)
        {
            if (gacMatrixEntry2 is GACMatrixEntry)
                return CompareTo((GACMatrixEntry)gacMatrixEntry2);
            else
                return 0;
        }
        public int CompareTo(GACMatrixEntry gacMatrixEntry2)
        {
            return GACEntryName.CompareTo(gacMatrixEntry2.GACEntryName);
        }
        #endregion

        // Convert to Title Case
        private string ToTitle(string thisString, char separator)
        {
            string[] words = thisString.ToLower().Split(separator);
            string output = "";

            foreach (string word in words)
            {
                if (word.Length > 1)
                    output += word.Substring(0, 1).ToUpper() + word.Substring(1);
                else
                    output += word.ToUpper();
                output += separator;
            }
            output = output.Trim(separator);

            return output;
        }
    }
}
